import React from 'react';
import {ModalForm, ProFormText} from '@ant-design/pro-components';
import {Button} from "antd";
import {DiffOutlined, EditOutlined} from "@ant-design/icons";

interface IDictType {
  isAdd: boolean;
  dictType?: API.IDictType;
  triggerButton?: React.ReactElement;
  onSubmit: (values: API.IDictType) => Promise<boolean>;
}


const DictTypeEdit: React.FC<IDictType> = ({isAdd, dictType, triggerButton, onSubmit}) => {
  return (
    <ModalForm
      title={isAdd ? '新增数据' : '编辑数据'}
      onFinish={async (values: API.IDictType) => {
        await onSubmit?.(values);
        return true;
      }}
      width={480}
      autoFocusFirstInput
      initialValues={dictType}
      trigger={triggerButton ? triggerButton : isAdd ?
        <Button type="primary" icon={<DiffOutlined/>} color="default"> 新增字典类型</Button>
        : <Button icon={<EditOutlined/>}> 编辑字典类型</Button>}
      modalProps={{destroyOnClose: true}}
    >
      <ProFormText
        name="dictName"
        label="字典名称"
        placeholder="请输入字典名称"
        rules={[{required: true, message: '请输入字典名称'}]}
      />
      <ProFormText
        name="dictType"
        label="字典类型"
        placeholder="请输入字典类型"
        rules={[{required: true, message: '请输入字典类型'}]}
      />
    </ModalForm>
  );
};

export default DictTypeEdit;
